/*!
    \copyright  Copyright (c) 2022 - 2024 Qualcomm Technologies International, Ltd.
                All Rights Reserved.
                Qualcomm Technologies International, Ltd. Confidential and Proprietary.
    \file
    \addtogroup le_audio_client
    @{
    \brief   Provides interfaces to provide configuration to be used in LE Audio client mode. 
             Currently supported only for LE Audio broadcast mode.
*/

#ifndef LE_AUDIO_CLIENT_AUDIO_CONFIG_H_
#define LE_AUDIO_CLIENT_AUDIO_CONFIG_H_

#if defined(INCLUDE_LE_AUDIO_UNICAST_SOURCE) || defined(INCLUDE_LE_AUDIO_BROADCAST_SOURCE)

#include "cap_profile_client.h"
#include "tmap_client_source.h"

/* Indicates the format framed or unframed */
#define LE_AUDIO_CLIENT_UNFRAMED                (0x0)
#define LE_AUDIO_CLIENT_FRAMED                  (0x1)

#ifdef INCLUDE_LE_AUDIO_BROADCAST_SOURCE

/*! \brief Data associated with LE Audio Client Broadcast config.
           This is only retained for backward compatibility purpose
           and V2 version is the structure to be used ideally 
*/
typedef struct
{
    /*! QHS required */
    bool   qhs_required;

    /*! Target Latency in milliseconds
        The time range is 5 milliseconds to 4000 milliseconds.
        Range: 0x0005 to 0x0FA0
        All other values: RFU
     */
    CapClientTargetLatency target_latency;

    /*!  The RTN is a recommendation for the number of retransmissions a BIS data
         PDU should be given. This is intended to select between different levels of stream reliability.
         It cannot be guaranteed that every CIS Data PDU will be given this number of retransmissions.
         Range: 0x00 to 0x0F
         All other values: RFU
     */
    uint8 rtn;

    /*! Maximum codec frames per SDU in octects
        Range: 0x0000 to 0x0FFF
        All other values: RFU 
     */
    uint8 max_codec_frames_per_sdu;

    /*! Audio Context */
    TmapClientContext audio_context;

    /*! Broadcast type */
    CapClientBcastType broadcast_type;

    /*! Number of BIS/es */
    uint16 number_of_bis;

    /*! Number of audio channels per BIS */
    uint16 no_of_audio_channels_per_bis;

    /*!  The SDU size in octects.
         Range: 0x00 to 0x0FFF
         All other values: RFU
     */
    uint16 sdu_size; 

    /*!  The Maximum Transport Latency in milliseconds.
         The time range is 5 milliseconds to 4000 milliseconds.
         Range: 0x0005 to 0x0FA0
         All other values: RFU
     */
    uint16 max_latency;

    /*! A bitfield representing the server supported PHYs. The server shall not specify a PHY that is does not support
        00000001: LE 1M PHY preferred
        00000010: LE 2M PHY preferred
        00000100: LE Coded PHY preferred
     */
    CapClientPhy phy;

    /*! Stream Capability */
    TmapClientStreamCapability broadcast_stream_capability;

    /*!  The SDU Interval in microseconds
         Range: 0x000000FF to 0x000FFFFF
         All other values: RFU
     */
    uint32 sdu_interval;

    /*! Presentation delay in microseconds
        Range: 0x00000000 to 0x00FFFFFF
     */
    uint32 presentation_delay;
} LE_AUDIO_CLIENT_BROADCAST_CONFIG_T;

/*! \brief Data associated with LE Audio Client Broadcast configuration (version v2) */
typedef struct
{
    /*! QHS required */
    bool   qhs_required;

    /*  number of sub groups */
    uint8 number_of_sub_groups;

    /*! Applicable only for PBP auracast and not for TMAP  */
    CapClientBcastType broadcast_type;

    /*! Presentation delay in microseconds
        Range: 0x00000000 to 0x00FFFFFF
     */
    uint32 presentation_delay;

    /*! User set parameters to over ride default */
    CapClientBcastConfigParamV1 bcast_config;

    /*! BASE level sub group information */
    CapClientBigSubGroups *sub_groups;
} le_audio_client_broadcast_config_v2_t;

/*! \brief Structure to hold Broadcast name and encryption code information */
typedef struct
{
    /*! Length of Broadcast source name 
        Name length should be between 1 to 30 bytes */
    uint8                                   broadcast_source_name_len;

    /*! Broadcast source name */
    const char                              *broadcast_source_name;

    /*! Broadcast code that has been set for encryption of BIS stream 
        Broadcast code length should be between a fixed range of minimum 4 bytes to a maximum of 16 bytes.
        Application can specify the code in above mentioned range and is expected to append '0's 
        for remaining length upto 16. If broadcast code is NULL, then will be considered as unencrypted stream */
    const uint8                             *broadcast_code;
} LE_AUDIO_CLIENT_BROADCAST_NAME_CODE_T;

/*! \brief Callback interface

    Implemented and registered for LEA configuration updates from application
*/
typedef struct
{
    /*! \brief This is mantained for backward compability which provides minimal informtaion to configure broadcast source stream. 
                For more additional configuration use GetBroadcastAudioConfigV2 
    */
    void (*GetBroadcastAudioConfig)(LE_AUDIO_CLIENT_BROADCAST_CONFIG_T *broadcast_audio_config);

    /*! \brief Called to retrieve broadcast name and encryption code configuration */
    void (*GetBroadcastNameAndEncryptionCode)(LE_AUDIO_CLIENT_BROADCAST_NAME_CODE_T *broadcast_name_code);

    /*! \brief Called to retreive advertising parameters used for broadcast */
    void (*GetBroadcastAdvParams)(CapClientBcastSrcAdvParams **broadcast_adv_params);

    /*! \brief Called to retreive broadcast ID to use for broadcast */
    uint32 (*GetBroadcastId)(void);

    /*! \brief Called to retreive Broadcast BASE configurations for Sub group and BIS 
        \param broadcast_base_config Applicaiton is responsible for managing the memory associated 
               with this return parameter, It should not be freed post a call to this callback.
    */
    void (*GetBroadcastAudioConfigV2)(le_audio_client_broadcast_config_v2_t **broadcast_base_config);
} le_audio_client_config_interface_t;

/*! \brief Initialise the audio configuration for LE audio client */
void leAudioClient_AudioConfigInit(void);

/*! \brief Register callback functions from application for broadcast configurations

    \param broadcast_audio_config_cb  Callback functions.

    Note: The below interfaces exposes two versions for broadcast audio configuration

    GetBroadcastAudioConfig : This interface when registered provides minimal configuration and is maintianed for backward compatibility
    GetBroadcastAudioConfigV2 : This is a more detailed verison of above interface which provides flexibility for specifying BASE level 1, 2 and 3 configurations
*/
void LeAudioClient_RegisterConfigInterface(const le_audio_client_config_interface_t * lea_audio_config);

#endif /* INCLUDE_LE_AUDIO_BROADCAST_SOURCE */

#endif /* defined(INCLUDE_LE_AUDIO_UNICAST_SOURCE) || defined(INCLUDE_LE_AUDIO_BROADCAST_SOURCE) */

#endif /* LE_AUDIO_CLIENT_AUDIO_CONFIG_H_ */

/*! @} */
